﻿using System;
using System.Data;
using BLL;
using BLL.Access;
using Web.Class;
using Entity;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class JIHuanZYDJ : BasePage
    {
        #region 属性
        public string LaiHanID
        {
            get { return hdCollection.Contains("LaiHanID") ? hdCollection.Get("LaiHanID").ToString() : ""; }
            set { hdCollection.Set("LaiHanID", value); }
        }
        public string LaiHanLCBH
        {
            get { return hdCollection.Contains("LaiHanLCBH") ? hdCollection.Get("LaiHanLCBH").ToString() : ""; }
            set { hdCollection.Set("LaiHanLCBH", value); }
        }
        #endregion

        #region 变量

        bool isSuccess = false;

        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 上传
        /// </summary>
        SYS_UPLOADProcess bllupload = new SYS_UPLOADProcess();

        /// <summary>
        /// 来函信息
        /// </summary>
        YS_LH_LAIHANXXProcess bllh = new YS_LH_LAIHANXXProcess();

        /// <summary>
        /// 流程
        /// </summary>
        YS_LH_LAIHANLCJLBLL lcbll = new YS_LH_LAIHANLCJLBLL();
        /// <summary>
        /// 日志
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        /// <summary>
        /// 来函保存用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess laihanyhxx = new YS_LH_YONGHUXXProcess();

        YS_LH_JIHUAZYProcess bllzyjh = new YS_LH_JIHUAZYProcess();

        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["gaopai"] = null;
               
            }
        }
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsPostBack)
            {
                BindUserInfo();
            }
        }
       /// <summary>
       /// callback事件
       /// </summary>
       /// <param name="source"></param>
       /// <param name="e"></param>
        protected void ASPxCallbackCommon_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {            
            if (e.Parameter == "shoujian")
            {
                e.Result = e.Parameter + "|" + AddLAIHANXX(0);
            }
            if (e.Parameter == "dengji")
            {
                e.Result = e.Parameter + "|" + AddLAIHANXX(1);
            }
        }
        /// <summary>
        /// 退回
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnBack_Click(object sender, EventArgs e)
        {
            Save(-2);
        }
        /// <summary>
        /// 受理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSL_Click(object sender, EventArgs e)
        {
            Save(2);
        }
        /// <summary>
        /// 不受理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnBSL_Click(object sender, EventArgs e)
        {
            Save(-1);
        }
        /// <summary>
        /// 加载选中的材料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnCheck_Click(object sender, EventArgs e)
        {
            UCLHCaiLiaoInfo.BindCheckBox(UCLHJiHuaZYUserInfo.TxtYongHuH, "");
            UCLHJiHuaZYUserInfo.YongHuHYFocus();
        }
        protected void BtnReload_Click(object sender, EventArgs e)
        {
            BindUserInfo();
        }
        /// <summary>
        /// 计划绑定判断
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BindJH(object sender, EventArgs e)
        {
            if (UCLHJiHuaZYUserInfo.YongHuHJ.Length == 0 )
            {
                PageTools.AlertMsg(this,"无转出用户");
                UCLHJiHuaZYUserInfo.YongHuHJFocus();
                return;
            }
            if (UCLHJiHuaZYUserInfo.YongHuHY.Length == 0)
            {
                PageTools.AlertMsg(this, "无转入用户");
                UCLHJiHuaZYUserInfo.YongHuHYFocus();
                return;
            }
            if (UCLHJiHuaZYUserInfo.Y == 0)
            {
                PageTools.AlertMsg(this, "请输入水量年");
                UCLHJiHuaZYUserInfo.YMFocus();
                return;
            }
            DataSet ds = UCLHJiHuaZYUserInfo.BindJHXX(1);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                UCLHJiHuanZYJHXX.BindJHXX(ds, 1);
            }
            else
            {
                PageTools.AlertMsg(this,"转出用户对应水量年没有计划量");
                UCLHJiHuanZYJHXX.ClearJHXX(1);
                UCLHJiHuaZYUserInfo.YongHuHJFocus();
                isSuccess = false;
                return;
            }
            DataSet ds1 = UCLHJiHuaZYUserInfo.BindJHXX(2);
            if (ds1 != null && ds1.Tables.Count > 0 && ds1.Tables[0] != null && ds1.Tables[0].Rows.Count > 0)
            {
                UCLHJiHuanZYJHXX.BindJHXX(ds1, 2);
            }
            else
            {
                PageTools.AlertMsg(this, "转入用户对应水量年没有计划量");
                UCLHJiHuanZYJHXX.ClearJHXX(2);
                UCLHJiHuaZYUserInfo.YongHuHYFocus();
                isSuccess = false;
                return;
            }
            UCLHJiHuanZYJHXX.SetFocusControl();
        }
        #endregion

        #region 方法

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="type">-2退回 2受理 -1不受理</param>
        private void Save(int type)
        {
            int liuchengbh = type == -2 ? (int)eLaiHanLCBH.退回 : type == 2 ? (int)eLaiHanLCBH.受理 : (int)eLaiHanLCBH.不受理;
            string laihanzbupdatecol = string.Format("I_LIUCHENGBH={0},S_SHENQINGLY='{1}',S_BEIZHU='{2}'", (int)eLaiHanLCBH.受理, "", "");
            string where = string.Format(" ID={0} ", LaiHanID);
            if (type == -1)
            {
                laihanzbupdatecol = string.Format("S_SHENQINGLY='{1}',S_BEIZHU='{2}' ,i_LIUCHENGZT={0}", (int)eLaiHanLCBH.不受理, "", "");
            }
            else if (type == -2)
            {
                laihanzbupdatecol = string.Format("I_LIUCHENGBH={0},S_SHENQINGLY='{1}',S_BEIZHU='{2}'", (int)eLaiHanLCBH.预登记, "","");
            }
            int success = bllh.UpdateYS_LH_LAIHANXXesDynamic(laihanzbupdatecol, where);
            if (success > 0)
            {
                ///添加受理开始信息
                YS_LH_LAIHANLCJL lcjl = new YS_LH_LAIHANLCJL();
                lcjl.D_CAOZUORQ = DateTime.Now;
                lcjl.D_STARTDATE = DateTime.Now;
                lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
                lcjl.I_LAIHANLX = 3;
                lcjl.I_LIUCHENGBH = liuchengbh;
                lcjl.ID = 0;
                if (type == -2 || type == -1)
                {
                    lcjl.D_ENDDATE = DateTime.Now;
                }

                DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", h_laihan.Value, liuchengbh), "", null);
                if (lcxx != null && lcxx.Rows.Count > 0)
                {
                    lcjl.ID = Convert.ToInt32(lcxx.Rows[0]["ID"]);
                }
                lcjl.S_LAIHANBH = h_laihan.Value;
                lcjl.S_LIUCHENGMC = type == 2 ? "受理" : type == -1 ? "不受理" : "退回";
                lcbll.InsertOrUpdate(lcjl);

                ///更新受理结束事件  受理事件开始结束同时
                lcbll.UpdateYS_LH_LAIHANLCJLsDynamic(string.Format("D_ENDDATE=sysdate,I_CAOZUOR={0},D_CAOZUORQ=sysdate", LoginInfo.CurrentUser.UserID), " I_LIUCHENGBH=20 and S_LAIHANBH='" + lcjl.S_LAIHANBH + "'");
                ///受理结束直接进入下个流程
                if (type > 0)
                {
                    AddYEWUYUAN();
                    //lcbll.UpdateYS_LH_LAIHANLCJLsDynamic(string.Format("D_ENDDATE=sysdate,I_CAOZUOR={0},D_CAOZUORQ=sysdate", LoginInfo.CurrentUser.UserID), " I_LIUCHENGBH=1 and S_LAIHANBH='" + lcjl.S_LAIHANBH + "'");
                }
                System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "aa", "alert('操作成功!');parent.layer.closeAll();",true);
                //PageTools.AlertMsg(this, "操作完成", "ReloadFather();");

                //System.Web.UI.ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), DateTime.Now.ToString("yyyyMMddHHmmssfff"), new System.Text.StringBuilder("window.close();").ToString(), true);

            }

        }
        /// <summary>
        /// 添加业务员开始信息
        /// </summary>
        private void AddYEWUYUAN()
        {
            var bllT = new YS_LH_LAIHANXXProcess();
            var laihanxx = bllT.SelectYS_LH_LAIHANXX(int.Parse(LaiHanID));
            SpHelper spHelper = new SpHelper();
            /*更新待处理操作人*/
            int? state = -1;
            string msg = null;
            int? nextflowno = 0;
            string nextflowname = "";
            int liuchengzt = 0;//记录当前来函流程状态.为1时表示已结束.
            spHelper.P_YSLH_DAICHULCZR(laihanxx.S_LAIHANBH, (int?)laihanxx.I_LAIHANLX, (int?)laihanxx.I_LIUCHENGBH, liuchengzt, laihanxx.S_YONGHUBH, out nextflowno, out nextflowname, out state, out msg);
            if (state < 0)
            {
                throw new Exception(msg);
            }
            if (nextflowno > 0)
            {
                //更新当前来函状态为下一步
                bllh.UpdateYS_LH_LAIHANXXesDynamic("I_LIUCHENGBH=" + nextflowno,
                    "I_JLZT=0 AND S_LAIHANBH=" + laihanxx.S_LAIHANBH);

                //添加流程记录业务员意见开始信息
                YS_LH_LAIHANLCJL lcjl = new YS_LH_LAIHANLCJL();
                lcjl.D_CAOZUORQ = DateTime.Now;
                lcjl.D_STARTDATE = DateTime.Now;
                lcjl.I_LAIHANLX = laihanxx.I_LAIHANLX;
                lcjl.I_LIUCHENGBH = nextflowno;
                lcjl.S_LIUCHENGMC = nextflowname;
                lcjl.S_LAIHANBH = h_laihan.Value;
                lcjl.ID = 0;

                DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", h_laihan, lcjl.I_LIUCHENGBH), "", null);
                if (lcxx != null && lcxx.Rows.Count > 0)
                {
                    lcjl.ID = Convert.ToInt32(lcxx.Rows[0]["ID"]);
                }
                lcbll.InsertOrUpdate(lcjl);
            }
        }


        /// <summary>
        /// 添加来函信息
        /// </summary>
        private string AddLAIHANXX(int liuchengzt)
        {
            bool isAdd = true;

            if ((!string.IsNullOrEmpty(Request["laihanbh"]) && !string.IsNullOrEmpty(Request["id"])) && (LaiHanID != "" && LaiHanID != "0"))
            {
                LaiHanID = Request["id"];
            }
            if (LaiHanID == "" || LaiHanID == "0")
            {
                isAdd = true;
            }
            else
            {
                isAdd = false;
            }
            string msg = "";
            if (UCLHJiHuaZYUserInfo.YongHuHJ.Trim().Length == 0 && isAdd)
            {
                return "-1|请输入用户号(甲)并搜索相关信息";
            }
            if (UCLHJiHuaZYUserInfo.YongHuHY.Trim().Length == 0 && isAdd)
            {
                return "-2|请输入用户号(乙)并搜索相关信息";
            }
            int y, m;
            string yd = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            int year = Convert.ToInt32(yd.Substring(0, 4));
            int month = int.Parse(yd.Substring(4, 2));

            if (UCLHJiHuaZYUserInfo.Y> year||UCLHJiHuaZYUserInfo.Y==0)
            {

                return "-3|年月不能大于当前水量年月";
            }
            if (!UCLHJiHuanZYJHXX.SumbitYN)
            {

                return "-4|计划信息不完整";
            }

            int shenqing = 0;
            if (!UCLHJiHuanZYJHXX.CheckInsertValue())
            {
                return "-5|转移计划输入错误";
            }


            //添加来函主表
            YS_LH_LAIHANXX laihan = new YS_LH_LAIHANXX();
            laihan.I_XT = BusinessTool.WType;
            laihan.D_SHURURQ = DateTime.Now;
            laihan.D_LAIHANRQ = DateTime.Now;
            laihan.I_JLZT = 0;
            laihan.I_LAIHANLX = 3;
            laihan.I_LIUCHENGBH = liuchengzt;
            
            laihan.I_SHURUR = LoginInfo.CurrentUser.UserID;
            laihan.I_Y = Convert.ToInt32(UCLHJiHuaZYUserInfo.Y);
            laihan.I_TZY = laihan.I_Y;
            laihan.ID = 0;
            //laihan.S_GUANLIKBH = UCLHJiHuaZYUserInfo.GuanLiKJ;
            //laihan.S_ZHANDIANBH = UCLHJiHuaZYUserInfo.ZhanDianBH;
            laihan.I_AUTOTYPE = 0;
            DataTable dt = bllh.SelectYS_LH_LAIHANXXesDynamic(string.Format(" S_YONGHUBH='{0}'  and I_Y={1} and I_LaiHANLX=3 and S_ZHANDIANBH='{2}'", UCLHJiHuaZYUserInfo.YongHuHJ, UCLHJiHuaZYUserInfo.Y,laihan.S_ZHANDIANBH), "", null);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (isAdd)
                {
                    return string.Format("-6|该用户来函已存在，来函编号：{0}", dt.Rows[0]["S_LAIHANBH"]);
                }

                laihan.ID = Convert.ToInt32(Convert.ToInt32(dt.Rows[0]["ID"]));
            }
            if (LaiHanID!=""&&LaiHanID!="0")
            {
                laihan.ID = Convert.ToInt32(Request["ID"]);
            }
            
            string laihanbh = "";
            string xukebh = "";
            if (isAdd)
            {
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(UCLHJiHuaZYUserInfo.YongHuHJ, out zd, out glk, out ywy);
                laihan.S_ZHANDIANBH = zd;
                laihan.S_GUANLIKBH = glk;
                laihan.I_YWY = int.Parse(ywy);
                laihan.S_YWY = BusinessTool.GetYWYName(ywy);
                //laihan.S_YHYWY = ywy;
                DataSet numset = new SpHelper().P_YS_LH_XUKEBH(glk, 3, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);
                ///生成来函编号   许可编号
                //DataSet numset = _sphelper.P_YS_LH_XUKEBH(UCLHJiHuaZYUserInfo.GuanLiKJ, 3, 0, UCLHJiHuaZYUserInfo.Y.ToString(), out xukebh, out laihanbh);

                h_laihan.Value = laihanbh;
            }
            else
            {
                laihanbh = h_laihan.Value;
                xukebh = UCLHJiHuaZYUserInfo.XuKeBM;
                laihan.S_ZHANDIANBH = UCLHJiHuaZYUserInfo.ZhanDianBH;
            }
            laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
            laihan.S_LAIHANBH = laihanbh;
            laihan.S_BEIYONG1 = xukebh;
            laihan.S_XUKEBH = xukebh;
            laihan.S_YONGHUBH = UCLHJiHuaZYUserInfo.YongHuHJ;
            laihan.S_YONGHUM = UCLHJiHuaZYUserInfo.ZhuanChuYHMJ;

            if (!UCLHCaiLiaoInfo.ValidateSubmit(laihan.S_LAIHANBH,laihan.S_YONGHUBH).IsSuccess)
            {

                return "-7|临时用水计划指标的核定申请表需上传";
            }
            laihan.D_CAOZUOSJ = DateTime.Now;
            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.S_TONGYIBM = UCLHJiHuaZYUserInfo.TONGYIBM;//统一审批编码
            
            
            if (laihan.ID == 0 || liuchengzt == 1)
            {
                bllh.InsertOrUpdate(laihan);
            }

            InsertJHZY(laihan.S_LAIHANBH,liuchengzt);
           
            ///如果有新上传的文件信息插入数据库

            UCLHCaiLiaoInfo.SHOUJIAN(laihan);

            ///记录用户信息
            InsertYONGHUXXJ(laihan.S_LAIHANBH);

            InsertYONGHUXXY(laihan.S_LAIHANBH);

            ///添加流程信息
            InsertLCJL(liuchengzt,laihan.S_LAIHANBH);
            ///日志信息
            _SYS_LOGBLL.Log<YS_LH_LAIHANXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-计划转移登记", OperateState.Modify, laihan, null);

           Session["gaopai"] = null;


         
            return "1|操作成功|"+laihan.ID;
        }
        /// <summary>
        /// 记录修改的甲用户信息
        /// </summary>
        /// <param name="laihanbh"></param>
        private void InsertYONGHUXXJ(string laihanbh)
        {

            ///甲用户
            YS_LH_YONGHUXX lhyhxx = new YS_LH_YONGHUXX();

            lhyhxx.ID = 0;
            lhyhxx.D_XIUGAIRQ = DateTime.Now;
            lhyhxx.S_DIZHI = UCLHJiHuaZYUserInfo.ZhuanChuDZJ;
            lhyhxx.S_LAIHANBH = laihanbh;


            lhyhxx.S_LIANXIDH = UCLHJiHuaZYUserInfo.ZhuanChuLXDHJ;
            lhyhxx.S_LIANXIR = UCLHJiHuaZYUserInfo.ZhuanChuLXRJ;
            lhyhxx.S_YONGHUBH = UCLHJiHuaZYUserInfo.YongHuHJ;
            lhyhxx.S_YONGHUM = UCLHJiHuaZYUserInfo.ZhuanChuYHMJ;

            DataTable oldyh = laihanyhxx.SelectYS_LH_YONGHUXXesDynamic(string.Format(" I_JLZT=0 and S_LAIHANBH='{0}' and S_YONGHUBH='{1}' ", laihanbh,UCLHJiHuaZYUserInfo.YongHuHJ), "", null);
            if (oldyh != null && oldyh.Rows.Count > 0)
            {
                lhyhxx.ID = Convert.ToInt32(oldyh.Rows[0]["ID"]);                
            }
            _SYS_LOGBLL.Log<YS_LH_YONGHUXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-记录（甲）用户信息", OperateState.Add, lhyhxx, null);
            //_SYS_LOGBLL.Log<YS_LH_YONGHUXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-记录（甲）用户信息", OperateState.Modify, lhyhxx, null);
            laihanyhxx.InsertOrUpdate(lhyhxx);
            if (lhyhxx.ID == 0)
            {
                
            }
            else
            {
                

            }

        }
        /// <summary>
        /// 记录乙用户
        /// </summary>
        /// <param name="laihanbh"></param>
        private void InsertYONGHUXXY(string laihanbh)
        {

            ///乙用户
            YS_LH_YONGHUXX lhyhxx = new YS_LH_YONGHUXX();

            lhyhxx.ID = 0;
            lhyhxx.D_XIUGAIRQ = DateTime.Now;
            lhyhxx.S_DIZHI = UCLHJiHuaZYUserInfo.ZhuanRuDZY;
            lhyhxx.S_LAIHANBH = laihanbh;


            lhyhxx.S_LIANXIDH = UCLHJiHuaZYUserInfo.ZhuanRuLXDHY;
            lhyhxx.S_LIANXIR = UCLHJiHuaZYUserInfo.ZhuanRuLXRY;
            lhyhxx.S_YONGHUBH = UCLHJiHuaZYUserInfo.YongHuHY;
            lhyhxx.S_YONGHUM = UCLHJiHuaZYUserInfo.ZhuanRuYHMY;

            DataTable oldyh = laihanyhxx.SelectYS_LH_YONGHUXXesDynamic(string.Format(" I_JLZT=0 and S_LAIHANBH='{0}'  and S_YONGHUBH='{1}' ", laihanbh,UCLHJiHuaZYUserInfo.YongHuHY), "", null);
            if (oldyh != null && oldyh.Rows.Count > 0)
            {
                lhyhxx.ID = Convert.ToInt32(oldyh.Rows[0]["ID"]);
            }
            _SYS_LOGBLL.Log<YS_LH_YONGHUXX>(LoginInfo.CurrentUser,BusinessTool.WType.ToString(), "计划转移流程-记录（乙）用户信息", OperateState.Add, lhyhxx, null);
            //_SYS_LOGBLL.Log<YS_LH_YONGHUXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-记录（乙）用户信息", OperateState.Modify, lhyhxx, null);
            laihanyhxx.InsertOrUpdate(lhyhxx);
            if (lhyhxx.ID == 0)
            {
               
            }
            else
            {
                

            }

        }
        /// <summary>
        /// 添加流程操作记录
        /// </summary>
        /// <param name="liuchengzt"></param>
        /// <param name="laihanbh"></param>
        private void InsertLCJL(int liuchengzt,string laihanbh)
        {
            ///添加流程记录信息
            YS_LH_LAIHANLCJL lcjl = new YS_LH_LAIHANLCJL();
            lcjl.S_CAOZUORQM = LoginInfo.CurrentUser.ElectronSign;
            lcjl.D_CAOZUORQ = DateTime.Now;
            lcjl.D_STARTDATE = DateTime.Now;
            lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
            lcjl.I_LAIHANLX = 3;
            lcjl.I_LIUCHENGBH = liuchengzt;
            lcjl.ID = 0;

            DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", laihanbh, liuchengzt), "", null);
            if (lcxx != null && lcxx.Rows.Count > 0)
            {
                lcjl.ID = Convert.ToInt32(lcxx.Rows[0]["ID"]);
            }
            lcjl.S_LAIHANBH = laihanbh;

            lcjl.S_LIUCHENGMC = liuchengzt == 1 ? "登记" : "预登记";
            if (lcjl.ID == 0)
            {
                lcbll.InsertOrUpdate(lcjl);
            }
            if (liuchengzt > 0)
            {
                lcbll.UpdateYS_LH_LAIHANLCJLsDynamic(string.Format("D_ENDDATE=sysdate,I_CAOZUOR={0},D_CAOZUORQ=sysdate", LoginInfo.CurrentUser.UserID), " I_LIUCHENGBH=0 and S_LAIHANBH='" + laihanbh + "'");
            }
            if (lcjl.ID == 0)
            {
                _SYS_LOGBLL.Log<YS_LH_LAIHANLCJL>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-添加流程状态表数据", OperateState.Add, lcjl, null);
            }
            else
            {
                _SYS_LOGBLL.Log<YS_LH_LAIHANLCJL>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-更新流程状态表数据", OperateState.Modify, lcjl, null);

            }
        }
        /// <summary>
        /// 添加或者修改计划转移表信息
        /// </summary>
        /// <param name="lhbh"></param>
        private void InsertJHZY(string lhbh,int lcjl)
        {
            YS_LH_JIHUAZY jhzy = new YS_LH_JIHUAZY();
            jhzy.S_CAOZUORQM = LoginInfo.CurrentUser.ElectronSign;
            jhzy.D_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            jhzy.D_CAOZUORQ = DateTime.Now;
            jhzy.D_SHURURQ = DateTime.Now;
            jhzy.I_JLZT = 0;
            jhzy.I_M1 = UCLHJiHuanZYJHXX.M1;
            jhzy.I_M2 = UCLHJiHuanZYJHXX.M2;
            jhzy.I_M3 = UCLHJiHuanZYJHXX.M3;
            jhzy.I_M4 = UCLHJiHuanZYJHXX.M4;
            jhzy.I_M5 = UCLHJiHuanZYJHXX.M5;
            jhzy.I_M6 = UCLHJiHuanZYJHXX.M6;
            jhzy.I_M7 = UCLHJiHuanZYJHXX.M7;
            jhzy.I_M8 = UCLHJiHuanZYJHXX.M8;
            jhzy.I_M9 = UCLHJiHuanZYJHXX.M9;
            jhzy.I_M10 = UCLHJiHuanZYJHXX.M10;
            jhzy.I_M11 = UCLHJiHuanZYJHXX.M11;
            jhzy.I_M12 = UCLHJiHuanZYJHXX.M12;
            jhzy.I_Y = UCLHJiHuaZYUserInfo.Y;
            jhzy.ID = 0;
            jhzy.S_GUANLIKBH = UCLHJiHuaZYUserInfo.GuanLiKJ;
            jhzy.S_YONGHUBHJ = UCLHJiHuaZYUserInfo.YongHuHJ;
            jhzy.S_YONGHUBHY = UCLHJiHuaZYUserInfo.YongHuHY;
            jhzy.S_ZHANDIANBH = UCLHJiHuaZYUserInfo.ZhanDianBH;

            jhzy.I_LIUCHENGBH = lcjl;
            jhzy.S_LAIHANBH = lhbh;
            jhzy.S_SHENPIYJ = "";
            string where = " S_YONGHUBHJ='{0}' and S_YONGHUBHY='{1}' and I_Y={2}";
            where = string.Format(where,UCLHJiHuaZYUserInfo.YongHuHJ,UCLHJiHuaZYUserInfo.YongHuHY,UCLHJiHuaZYUserInfo.Y);

            DataTable dt = bllzyjh.SelectYS_LH_JIHUAZiesDynamic(where,"",null);

            if (dt != null && dt.Rows.Count > 0)
            {
                jhzy.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
            }

            _SYS_LOGBLL.Log<YS_LH_JIHUAZY>(LoginInfo.CurrentUser,BusinessTool.WType.ToString(), "计划转移流程-计划转移信息", OperateState.Add, jhzy, null);
            //_SYS_LOGBLL.Log<YS_LH_JIHUAZY>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-计划转移信息", OperateState.Modify, jhzy, null);
            bllzyjh.InsertOrUpdate(jhzy);
            if (jhzy.ID == 0)
            {
                
            }
            else
            {
                
           
            }
        }
        /// <summary>
        /// 收件操作
        /// </summary>
        /// <param name="laihan"></param>
        private void SHOUJIAN(YS_LH_LAIHANXX laihan)
        {

            int y, m;
            string yd = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            int year = Convert.ToInt32(yd.Substring(0, 4));
            int month = int.Parse(yd.Substring(4, 2));

            SYS_UPLOAD upload = new SYS_UPLOAD();
            upload.I_SUOSHUMK = 1;
            upload.I_TYPE = 1;
            upload.S_CAOZUOR = LoginInfo.CurrentUser.Account;
            upload.S_LAIHANBH = laihan.S_LAIHANBH;
            upload.S_YONGHUBH = laihan.S_YONGHUBH;
            upload.D_CAOZUORQ = DateTime.Now;

            if (Session["gaopai"] != null)
            {
                DataTable uploadtable = Session["gaopai"] as DataTable;

                foreach (DataRow dr in uploadtable.Rows)
                {
                    upload.ID = 0;
                    ///证件类型的文件只和用户相关，更新
                    if (dr["value"].ToString() !="4")
                    {
                        DataTable shangchuan = bllupload.SelectSYS_UPLOADsDynamic(string.Format(" S_YONGHUBH='{0}' and I_WENJIANLX={1} ", UCLHJiHuaZYUserInfo.YongHuHJ, dr["value"]), "", null);
                        if (shangchuan != null && shangchuan.Rows.Count > 0)
                        {
                            upload.ID = Convert.ToInt32(shangchuan.Rows[0]["ID"]);
                        }
                    }


                    upload.S_WENJIANMC = dr["name"].ToString();
                    upload.S_WENJIANLJ = dr["path"].ToString();
                    upload.I_WENJIANLX = Convert.ToInt32(dr["value"]);
                    upload.I_SHANGCHUANLB = Convert.ToInt32(dr["type"]);

                    _SYS_LOGBLL.Log<SYS_UPLOAD>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "计划转移流程-计划转移上传", OperateState.Modify, upload, null);
                    bllupload.InsertOrUpdate(upload);


                    
                    Session["gaopai"] = null;
                }
            }

        }
        /// <summary>
        /// 绑定信息
        /// </summary>
        private void BindUserInfo()
        {
            if (!string.IsNullOrEmpty(Request["id"])||(LaiHanID!=""&&LaiHanID!="0"))
            {
                if (!string.IsNullOrEmpty(Request["id"]) && (LaiHanID == "" || LaiHanID == "0"))
                {
                    LaiHanID = Request["id"];
                }
                int id = Convert.ToInt32(LaiHanID);
                YS_LH_LAIHANXX laihan = bllh.SelectYS_LH_LAIHANXX(id);
                if (laihan != null)
                {

                    h_laihan.Value = laihan.S_LAIHANBH;
                    string Jyonghu = laihan.S_YONGHUBH;
                    h_yonghu.Value = laihan.S_YONGHUBH;
                    string Yyonghu = "";
                    string where = " S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}'  ";
                    where = string.Format(where,laihan.S_LAIHANBH,laihan.S_YONGHUBH);
                    DataTable JiHuaZY = bllzyjh.SelectYS_LH_JIHUAZiesDynamic(where,"",null);
                    if (JiHuaZY != null && JiHuaZY.Rows.Count > 0)
                    {
                        Yyonghu = JiHuaZY.Rows[0]["S_YONGHUBHY"].ToString();

                       
                    }
                    else
                    {
                        PageTools.AlertMsg(this, "相关来函信息不存在");
                        return;
                    }
                    LaiHanID = laihan.ID.ToString();
                    laihan.I_LIUCHENGBH.ToString();
                    UCLHJiHuaZYUserInfo.LoadInfo(Jyonghu,Yyonghu,laihan);
                    UCLHCaiLiaoInfo.BindCheckBox(laihan.S_YONGHUBH, laihan.S_LAIHANBH);

                    UCLHJiHuanZYJHXX.BindJHXX(UCLHJiHuaZYUserInfo.BindJHXX(1), 1);
                    UCLHJiHuanZYJHXX.BindJHXX(UCLHJiHuaZYUserInfo.BindJHXX(2), 2);
                    UCLHJiHuanZYJHXX.BindJHL(JiHuaZY);
                    SetBtnDisplay(Convert.ToInt32(laihan.I_LIUCHENGBH));
                    UCLHBtnBottom.LoadInfo(laihan);
                   
                }
                else
                {
                    PageTools.AlertMsg(this,"相关来函信息不存在");
                    return;
                }
               
            }
            UCLHJiHuaZYUserInfo.YMFocus();
        }
        private void SetBtnDisplay(int lcbh)
        {
            if (lcbh > 0)
            {
                ShouLi.Visible = true;
                DengJi.Visible = false;
                UCLHJiHuanZYJHXX.SetShouLiStatus();
                UCLHJiHuaZYUserInfo.SetShouLiStatus();
            }
            else
            {
                ShouLi.Visible = false;
                DengJi.Visible = true;
            }
        }
        #endregion

        
    }
}